package com.bristua.mall.user.biz;

import com.bristua.mall.common.utils.CacheUtil;
import com.bristua.mall.user.dao.TUserBankMapper;
import com.bristua.mall.user.model.TUser;
import com.bristua.mall.user.model.TUserBank;
import com.bristua.mall.user.model.condition.TUserBankExample;
import com.bristua.mall.user.model.vo.QueryUserBankVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/3/24.
 */
@Service
public class QueryUserBanksBiz {

    @Resource
    private TUserBankMapper tUserBankMapper;

    @Autowired
    private CacheUtil cacheUtil;

    public List<QueryUserBankVO> queryUserBank(){
        TUser userSession = (TUser) cacheUtil.getUserSession();
        TUserBankExample tUserBankExample = new TUserBankExample();
        tUserBankExample.createCriteria().andUserIdEqualTo(userSession.getUserId());//用户ID
        List<TUserBank> tUserBanks = tUserBankMapper.selectByExample(tUserBankExample);
        if(tUserBanks!=null && tUserBanks.size()>0){
            List<QueryUserBankVO> queryUserBankVOS = new ArrayList<>();
            for(TUserBank tUserBank : tUserBanks){
                QueryUserBankVO queryUserBankVO = new QueryUserBankVO();
                BeanUtils.copyProperties(tUserBank,queryUserBankVO);
                queryUserBankVO.setBankId(tUserBank.getUserBankId());
                queryUserBankVOS.add(queryUserBankVO);
            }
            return queryUserBankVOS;
        }
        return null;
    }
}
